package com.skyworth.utils;

import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by skyworth on 2016/2/25.
 */
public class DateTimeManager {
    public static final String DATETIMEFMT = "yyyy-MM-dd";
    public static final String HHMMFMT = "HH:mm";
    public static final String DATESHORT="SHORT";
    public static final String DATEMEDIUM="MEDIUM";
    public static final String DATEFULL="FULL";

    public static Date StrToDate(String strDate,String fmt){

        SimpleDateFormat sdf = new SimpleDateFormat(fmt);
        Date dateTime = null;

        try {
            dateTime =  sdf.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
 //       dateTime = java.sql.Date.valueOf(strDate);
//        return dateTime;
        return new Date(dateTime.getTime());
    }


    public static Time StrToTime(String strTime, String fmt){

        SimpleDateFormat sdf = new SimpleDateFormat(fmt);
        Date dateTime = null;

        try {
            dateTime =  sdf.parse(strTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Time(dateTime.getTime());
    }

    public static String dateToStr(Date date,String type,String fmt){
        String str = null;
        DateFormat format = new SimpleDateFormat(fmt);
        if(type.equals("SHORT")){
            //16-2-25
            format = DateFormat.getDateInstance(DateFormat.SHORT);
            str = format.format(date);
        }else if(type.equals("MEDIUM")){
            //2016-2-25
            format = DateFormat.getDateInstance(DateFormat.MEDIUM);
            str = format.format(date);
        }else if(type.equals("FULL")){
            //2016年2月25日 星期四
            format = DateFormat.getDateInstance(DateFormat.FULL);
            str = format.format(date);
        }
        return str;
    }
}
